//package com.itheima.reggie.config;
//
//import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.ibatis.reflection.MetaObject;
//import org.springframework.stereotype.Component;
//
//import java.time.LocalDateTime;
//
//@Slf4j
//@Component
//public class MyMetaObjectHandler implements MetaObjectHandler {
//
//    @Override
//    public void insertFill(MetaObject metaObject) {
//        log.info("start insert fill ==============");
//        this.strictInsertFill(metaObject, "createTime", LocalDateTime.class, LocalDateTime.now());//        metaObject.setValue("createTime",LocalDateTime.now());
//        this.strictInsertFill(metaObject, "updateTime", LocalDateTime.class, LocalDateTime.now());//        metaObject.setValue("createTime",LocalDateTime.now());
//        this.strictInsertFill(metaObject, "createUser", Long.class, 2L);//        metaObject.setValue("createTime",LocalDateTime.now());
//        this.strictInsertFill(metaObject, "updateUser", Long.class, 2L);//        metaObject.setValue("createTime",LocalDateTime.now());
////        metaObject.setValue("updateTime",LocalDateTime.now());
////        metaObject.setValue("updateUser",1l);
////        metaObject.setValue("createUser",1l);
//    }
//
//    @Override
//    public void updateFill(MetaObject metaObject) {
//        this.strictUpdateFill(metaObject, "updateTime", LocalDateTime.class, LocalDateTime.now());
//        this.strictUpdateFill(metaObject, "updateUser", Long.class, 2L);
////        log.info("start update fill ==============");
////        metaObject.setValue("updateTime",LocalDateTime.now());
////        metaObject.setValue("updateUser",1l);
////        this.strictUpdateFill(metaObject, "updateTime", LocalDateTime.class, now); // 起始版本 3.3.0(推荐)
//    }
//}

package com.itheima.reggie.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.itheima.reggie.common.BaseContext;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Slf4j
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("start insert fill ....");
        this.strictInsertFill(metaObject, "createTime", LocalDateTime.class, LocalDateTime.now());
        this.strictInsertFill(metaObject, "createUser", Long.class, BaseContext.getCurrentThread());
        this.strictInsertFill(metaObject, "updateTime", LocalDateTime.class, LocalDateTime.now());
        this.strictInsertFill(metaObject, "updateUser", Long.class, BaseContext.getCurrentThread());
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("start update fill ==============");
        metaObject.setValue("updateTime", LocalDateTime.now());
        metaObject.setValue("updateUser", BaseContext.getCurrentThread());
    }
}
